/*----------------------------页面区域---------------------------------*/
<template>
    <el-card>
        <template #header>
            <div class="card-header">
                <span>api请求结构体</span>
                <el-button class="button" type="text" @click="selectText">选中文本</el-button>
                <el-button class="button" type="text" @click="copyCode">一键复制</el-button>
            </div>
        </template>
        <div class="gfcodeboxapi">
    <pre ref="gfcode" class="gfcode">
/*  {{ props.data.name }}-------- 代码自动生成部分------------开始*/
// Creat 新建
type {{ props.data.name }}CreatReq struct {
	g.Meta `path:"/{{ props.data.apiFile }}/{{ props.data.name }}/creat" method:"{{ props.data.type}}" summary:"{{ props.data.name }}Creat" tags:"{{ props.data.name }}"`
	Form *entity.{{ props.data.sqlname }} `json:"form" in:"query"  dc:"Creat对象"`
}
type {{ props.data.name }}CreatRes struct {
	g.Meta `mime:"json" example:"obj"`
	IsSuccess  bool `json:"isSuccess"   dc:"是否成功"`
}
// Update 修改
type {{ props.data.name }}UpdateReq struct {
	g.Meta `path:"/{{ props.data.apiFile }}/{{ props.data.name }}/update" method:"{{ props.data.type}}" summary:"{{ props.data.name }}Update" tags:"{{ props.data.name }}"`
	Form *entity.{{ props.data.sqlname }} `json:"form" in:"query"  dc:"Update对象"`
}
type {{ props.data.name }}UpdateRes struct {
	g.Meta `mime:"json" example:"obj"`
	IsSuccess  bool `json:"isSuccess"   dc:"是否成功"`
}
// React 读
type {{ props.data.name }}ReadReq struct {
	g.Meta `path:"/{{ props.data.apiFile }}/{{ props.data.name }}/read" method:"{{ props.data.type}}" summary:"{{ props.data.name }}Read" tags:"{{ props.data.name }}"`
	Id int `json:"id" in:"query"  dc:"主键ID"`
}
type {{ props.data.name }}ReadRes struct {
	g.Meta `mime:"json" example:"obj"`
	Form  *entity.{{ props.data.sqlname }} `json:"form"   dc:"对象"`
}
// Delete 删除
type {{ props.data.name }}DeleteReq struct {
	g.Meta `path:"/{{ props.data.apiFile }}/{{ props.data.name }}/delete" method:"{{ props.data.type}}" summary:"{{ props.data.name }}Delete" tags:"{{ props.data.name }}"`
	Id int `json:"id" in:"query"  dc:"主键ID"`
}
type {{ props.data.name }}DeleteRes struct {
	g.Meta `mime:"json" example:"obj"`
	IsSuccess  bool `json:"isSuccess"   dc:"是否成功"`
}
// Delete 批量删除
type {{ props.data.name }}DeleteByIdsReq struct {
	g.Meta `path:"/{{ props.data.apiFile }}/{{ props.data.name }}/deleteByIds" method:"{{ props.data.type}}" summary:"{{ props.data.name }}DeleteByIdsReq" tags:"{{ props.data.name }}"`
	Ids []int `json:"ids" in:"query"  dc:"主键ID数组"`
}
type {{ props.data.name }}DeleteByIdsRes struct {
	g.Meta `mime:"json" example:"obj"`
	IsSuccess  bool `json:"isSuccess"   dc:"是否成功"`
}
// List 分页查询
type {{ props.data.name }}ListReq struct {
	g.Meta `path:"/{{ props.data.apiFile }}/{{ props.data.name }}/list" method:"{{ props.data.type}}" summary:"{{ props.data.name }}List" tags:"{{ props.data.name }}"`
	Page *model.Page `json:"page" in:"query"  dc:"分页数据"`
}
type {{ props.data.name }}ListRes struct {
	g.Meta `mime:"json" example:"obj"`
	List  []*entity.{{ props.data.sqlname }} `json:"list"   dc:"对象数组"`
}
/*   {{ props.data.name }}--------代码自动生成部分------------结束*/
    </pre>            
        </div>

    </el-card>
</template>
/*----------------------------逻辑区域---------------------------------*/
<script setup>
import {ref,getCurrentInstance  } from 'vue'
const { proxy } = getCurrentInstance()
const gfcode = ref(null)
const props = defineProps({
    data: {
        type: Object
    }
})
function copyCode(){
    proxy.$copyText(gfcode.value.innerHTML).then(function (e) {
          proxy.$message.success('复制成功')
          console.log(e)
        }, function (e) {
          proxy.$message.error("复制失败")
          console.log(e)
        })
}
function selectText(){
    var range = document.createRange();
    var referenceNode =  document.getElementsByClassName("gfcodeboxapi").item(0); 
    console.log(referenceNode);
    range.selectNodeContents(referenceNode);
    var selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(range) 
}
</script>
<style lang="scss" scoped>
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.text {
    font-size: 14px;
}
.item {
    margin-bottom: 18px;
}
.box-card {
    width: 480px;
}
.gfcode {
    background-color: #f3f4f6;
    padding: 20px;
}
</style>

